import {
    UPDATE_STATE,
    UPDATE_SESSIONSTORAGE,
    CLEAR_SESSIONSTORAGE,
} from './mutation-types';
const mutation = {
    [UPDATE_STATE](state, payload) {
        Object.assign(state, payload)
    },
    [UPDATE_SESSIONSTORAGE](state, payload) {
        let storageItems = payload.storageItems;
        if (storageItems && storageItems.length) {
            storageItems.map(value => {
                let { key, name } = value;
                window.sessionStorage.setItem(key, name);
                state[key] = name;
                console.log(state[key],name)
            })
        }
    },
    [CLEAR_SESSIONSTORAGE](state, payload) {
        let clearItems = payload.clearItems;
        if (clearItems && clearItems.length) {
            clearItems.map(value => {
                window.sessionStorage.removeItem(value);
                state[value] = '';
            })
        }
    }
}
export default mutation;
